package com.ftp.web.spider.utils;


import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ShowDisk {

    private static  final long gb=(long) Math.pow(1024,3);
    private static  final long mb=(long) Math.pow(1024,2);

    private static List<Map> iteratorDisk(){
        List<Map> diskMapList=new ArrayList<>();
        //1. 获取本机盘符
        File[] roots = File.listRoots();
        for (int i = 0; i < roots.length; i++) {
            Map<String,String> diskMap=new HashMap<>();
            diskMap.put("disk-name",roots[i].getPath());
            diskMap.put("total-space",spaceConvert(roots[i].getTotalSpace()));
            diskMap.put("useable-space",spaceConvert(roots[i].getUsableSpace()));
            diskMap.put("free-space",spaceConvert(roots[i].getFreeSpace()));
            diskMapList.add(diskMap);

           /* System.out.println(roots[i].getPath()+"; ");//磁盘路径
            System.out.println(roots[i].getTotalSpace()/(1024^3)+"G ");//磁盘总空间大小
            System.out.println(roots[i].getUsableSpace()/1024/1024/1024+"G ");//剩余磁盘空间大小
            System.out.println(roots[i].getFreeSpace()/1024/1024/1024);//剩余磁盘空间大小*/
        }
        return diskMapList;
    }


    private static String spaceConvert(long space){
        String temporary=null;
        if (space>mb){
            temporary=space/gb+"GB";
        }else {
            temporary=space/gb+"MB";
        }
        return temporary;
    }

    public static void main(String[] args) {
        List<Map> diskMapList=ShowDisk.iteratorDisk();
        for (Map diskMap:diskMapList){
            System.out.println(diskMap.get("disk-name"));
            System.out.println(diskMap.get("total-space"));
            System.out.println(diskMap.get("useable-space"));
            System.out.println(diskMap.get("free-space"));
        }
        File file=new File("/home/fw");
        for (File file1:file.listFiles())
            if (file1.isDirectory())
                System.out.println(file1.getPath());
        //file.list();
    }
}
